package thread;

/**
 * @Author: admin
 * @Description:
 * @Date: 2019/3/3 16:32
 */

public class ThreadHook extends Thread {


    @Override
    public void run() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getId() + Thread.currentThread().getName());
    }

    public static void main(String[] args) {
        Runtime.getRuntime().addShutdownHook(new Thread(){
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getId() + Thread.currentThread().getName());
                System.out.println("exit");
            }
        });
        System.out.println(Thread.currentThread().getId() + Thread.currentThread().getName());
        System.out.flush();
        ThreadHook thread1 = new ThreadHook();
        ThreadHook thread2 = new ThreadHook();

        //thread1.run();
        thread1.start();
        //thread1.start();
        thread2.start();
        System.out.println("main end");
    }
}
